package cn.sh.library.mgts.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import cn.sh.library.mgts.framework.interceptor.AuthorizationInterceptor;

@Configuration
public class WebConfiguration implements WebMvcConfigurer {

	@Autowired
	AuthorizationInterceptor authrizationInterceptor;

	// 这个方法用来注册拦截器，我们自己写好的拦截器需要通过这里添加注册才能生效
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		// 拦截配置 表示除了登陆之外都需要拦截
		registry.addInterceptor(authrizationInterceptor).addPathPatterns("/**").excludePathPatterns("/login","/loginVerify","/static/**","/horizon/**","/sync/**");
	}

	// 这个方法是用来配置静态资源的，比如html，js，css，等等
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); 
//		WebMvcConfigurer.super.addResourceHandlers(registry);
	}

//	@Override
//	public void addCorsMappings(CorsRegistry registry) {
//		registry.addMapping("/**")
//		.allowedMethods("POST", "GET", "TRACE", "OPTIONS") 
//		.allowedHeaders("Content-Type", "Origin", "Accept")
//		.allowCredentials(true).maxAge(3600);
//	}

}
